package com.example.basic.service.impl;

import com.example.basic.constant.BaseConstants;
import com.example.basic.controller.dto.CampCategoryDTO;
import com.example.basic.controller.dto.HeroInfoDTO;
import com.example.basic.dao.HeroInfoMapper;
import com.example.basic.service.HeroInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author mjw
 * @date 2022/9/28
 */
@Service
public class HeroInfoServiceImpl implements HeroInfoService {

    @Resource
    private HeroInfoMapper heroInfoMapper;

    @Override
    public List<Object> selectByCondition(int pageNum, int pageSize, String queryType) {
        List<Object> resultList = new ArrayList<>();
        if (BaseConstants.DETAIL.equals(queryType)) {
            PageHelper.startPage(pageNum, pageSize);
            List<HeroInfoDTO> heroInfoDTOList = heroInfoMapper.selectAll();
            PageInfo<HeroInfoDTO> pageInfo = new PageInfo<>(heroInfoDTOList);
            resultList.addAll(pageInfo.getList());
        } else if (BaseConstants.SUMMARY.equals(queryType)) {
            PageHelper.startPage(pageNum, pageSize);
            List<CampCategoryDTO> campCategoryDTOList = heroInfoMapper.countCampCategory();
            PageInfo<CampCategoryDTO> pageInfo = new PageInfo<>(campCategoryDTOList);
            resultList.addAll(pageInfo.getList());
        }
        return resultList;
    }
}
